<?php
    use User\Model\RedPacketModel;
?>
<style>
	.table>tbody>tr>td{vertical-align: middle}
</style>
<div id="page-wrapper">
	<div class="row">
		<div class="col-lg-12">
			<h1 class="page-header">活动列表</h1>
		</div>
		<!-- /.col-lg-12 -->
	</div>

	<div class="row">
		<div class="col-lg-12">
			<div class="panel panel-default">
				<div class="panel-heading">
					<a style="margin-left:7px" href="{:U('User/RedPacket/edit')}" class="btn btn-success">新增</a>
					<a href="javascript:;" id="deleteAll" class="btn btn-danger">删除</a>
				</div>
				<!-- /.panel-heading -->

				<div class="panel-body">
					<div class="col-lg-12">
						<div class="table-responsive">
							<table class="table">
								<thead>
								<tr>
									<th><input type="checkbox" id="selectAll"></th>
									<th>编号</th>
									<th>名称</th>
									<th>关键词</th>
									<th>链接地址</th>
									<th>状态</th>
									<th>开始时间</th>
									<th>结束时间</th>
									<th class="textAlignCenter">操作</th>
								</tr>
								</thead>
								<tbody>
								<volist name="list" id="item">
									<tr>
										<td><input type="checkbox" name="ids" value="{$item.id}"></td>
										<td>{$item.id}</td>
										<td>{$item.title}</td>
										<td>{$item.keyword}</td>
										<td>{$item.link}</td>
										<td>
											<if condition="$item.status eq RedPacketModel::STATUS_ACTIVE">
												<span class="label label-success">已发布</span>
											<else/>
												<span class="label label-warning">已停用</span>
											</if>
										</td>
										<td>{$item.startdate}</td>
										<td>{$item.enddate}</td>
										<td>
											<a href="{:U('User/RedPacket/edit', array('id'=>$item['id']))}" title="编辑活动" class="btn btn-default"><i class="fa fa-edit"></i></a>
											<a href="{:U('User/RedPacket/fanslist', array('id'=>$item['id']))}" title="参与粉丝" class="btn btn-default"><i class="fa fa-users"></i></a>
											<a href="{:U('User/RedPacket/awardlist', array('id'=>$item['id']))}" title="中奖管理" class="btn btn-default"><i class="fa fa-gift"></i></a>
											<if condition="$item.status eq RedPacketModel::STATUS_STOP">
											<a href="javascript:;" title="发布活动" onclick="return update_data({$item['id']}, <?php echo RedPacketModel::STATUS_ACTIVE ?>);" class="btn btn-default"><i class="fa fa-play"></i></a>
											<else/>
											<a href="javascript:;" title="停用活动" onclick="return update_data({$item['id']}, <?php echo RedPacketModel::STATUS_STOP ?>);" class="btn btn-default"><i class="fa fa-stop"></i></a>
											</if>
											<a href="javascript:;" title="删除活动" onclick="return update_data({$item['id']}, <?php echo RedPacketModel::STATUS_DELETE ?>);" class="btn btn-default"><i class="fa fa-times"></i></a>
										</td>
									</tr>

								</volist>

								</tbody>
							</table>


						</div>
						<!-- /.table-responsive -->

						<div class="pages">
							{$page}
						</div>
					</div>
					<!-- / .col-lg-12 -->
				</div>
				<!-- / .panel-body -->
			</div>
			<!-- /.panel-body -->
		</div>
		<!-- /.panel -->
	</div>
	<!-- /.col-lg-12 -->
</div>

</div>
<script>
    $("#selectAll").click(function(){
        if($(this).prop('checked') == true){
            $("input[name=ids]").prop('checked',true);
        }else{
            $("input[name=ids]").prop('checked',false);
        }
    })

    $("#deleteAll").click(function(){
        if(!confirm('确认删除吗？')) return false;
        var ids = "";
        $("input[name=ids]").each(function() {
            if($(this).prop("checked")){
                ids += $(this).val() + "|";
            }
        });
        if(ids != ''){
            $.ajax({
                data: {ids: ids},
                dataType: 'json',
                url: '/User/RedPacket/deletes',
                type: 'get',
                success: function (res) {
                    alert(res['info']);
                    window.location.reload();
                }
            });
        }else{
            alert('请勾选活动！');
		}
    });

    function update_data(id, status){
        if(status == 1){
            if(!confirm('确认发布吗？')) return false;
		}else if(status == 2){
            if(!confirm('确认停用吗？')) return false;
		}else{
            if(!confirm('确认删除吗？')) return false;
		}
        $.ajax({
            data: {id: id, status: status},
            dataType: 'json',
            url: '/User/RedPacket/updateData',
            type: 'get',
            success: function (res) {
                alert(res['info']);
                window.location.reload();
            }
        });
        return false;
    }
</script>